<?php
//main values
$urlserviceenable = $options['urlserviceenable'];
$urlservice = $options['urlservice'];
$urlautogen = $options['urlautogen'];

//tweet
$tweet = $options['tweet'];
$tweet_user = $options['tweet_user'];
$tweet_pass = $options['tweet_pass'];
$tweeted = get_post_meta($postid, 'tweet', true);

//post
$postid = $post->ID;

//shorturl
$shorturl = get_post_meta($postid, 'shorturl', true);
if(empty($shorturl)){$shorturl = get_post_meta($postid, 'short_url', true);}

wp_nonce_field('fts-urlshortener');
if($urlserviceenable == 'yes'){
	if ($urlservice != 'none'){
	?>
		<?php //in case no JS 
		if (!empty($shorturl)){?>
			<p class="shorturl-status"><strong>Your current short URL is: </strong><br /><a class="poplink" href="<?php echo $shorturl;?>"><?php echo $shorturl;?></a></p>
			<div class="fts-nojs"><input type="submit" class="button remove-shorturl" name="remove-shortlink" value="Remove Short URL" /></div>
		<?php elseif ($urlautogen == 'yes'){?>
			<h4>How To:</h4>
			<p>Short URL will be generated upon publishing the post/page.</p>
			<p>To disable automatic generation, set "Enable Automatic Short URL Generation upon publish" in the <a href="options-general.php?page=shorturl">URL Shortener options page</a> to "No".</p>
		<?php } elseif ($urlautogen == 'no'){?>	
			<h4>How To:</h4>
			<p>Check the generate short URL option to enable short URL generation upon publishing the post/page.</p>
			<div class="fts-nojs" style="font-weight: bold; padding: 1em; margin-top: 2em;background: #D2FFCF;">Generate Short URL on publish: <input id="urlshortlink" type="checkbox" name="get-shortlink" value="Enabled" /></div>
		<?php } else {?>
			<p>The URL Shortener Plugin is now configured and active.</p>
		<?php }
		
		//tweet portion
		if (!empty($tweeted)){?>
			<p><strong>This post has been published to twitter. </strong><br /><a class="poplink" href="<?php echo $tweeted;?>"><?php echo $tweeted;?></a></p>
		<?php }elseif ($tweet == 'disabled'){?>
			<p>Post to Twitter is currently <strong>disabled</strong></p>
		<?php }elseif ($tweet == 'auto'){?>
			<p>The post title and (short) URL will automatically be posted to Twitter.</p>
		<?php }elseif($tweet == 'manual'){?>
			<p>Post to Twitter: <input type="submit" class="button" name="post-tweet" value="Click to Post" /></p>
		<?php }
		
		//JS portion ?>
		<script type="text/javascript">/* <![CDATA[ */jQuery(document).ready(function($){
			$('.fts-nojs').html('');
			<?php //Shourt URL Post 
			if ($shorturl){?>
				<?php if (!function_exists('get_shortlink') ){?>
					$('#edit-slug-box').append('<a class="button poplink" href="<?php echo $shorturl;?>">Show Short URL</a>');	
				<?php }?>				
				$('#misc-publishing-actions').append('<div class="misc-pub-section shorturl-status">Short URL Status: <strong><a class="poplink" href="<?php echo $shorturl;?>">Generated</a></strong> &nbsp;<input type="submit" class="button remove-shorturl" name="remove-shortlink" value="Remove" /></div>');
			<?php elseif ($urlautogen == 'yes'){?>
				$('#misc-publishing-actions').append('<div class="misc-pub-section">Short URL Generation: <strong>Auto</strong></div>');
			<?php } elseif ($urlautogen == 'no'){?>		
				$('#misc-publishing-actions').append('<div class="misc-pub-section">Short URL Status: <strong>No Short URL</strong></div>');	
			<?php } ?>
			
			<?php //Twitter Post 
			if (!empty($tweeted)){?>
				$('#misc-publishing-actions').append('<div class="misc-pub-section">Post to Twitter: <a class="poplink" href="<?php echo $tweeted;?>"><strong>Published</strong></a></div>');
			<?php } elseif ($tweet = 'auto'){?>
				$('#misc-publishing-actions').append('<div class="misc-pub-section">Post to Twitter: <strong>Auto</strong></div>');
			<?php } elseif ($tweet = 'manual'){?>
				$('#misc-publishing-actions').append('<div class="misc-pub-section">Post to Twitter: <input type="submit" class="button" name="post-tweet" value="Click to Post" /></div>');
			<?php }?>	
			
			<?php //Manual URL Generate 
			if($urlautogen == 'no' && empty($shorturl)){?>	
				$('#misc-publishing-actions').append('<div style="font-weight: bold; padding: 1em; margin-top: 2em;background: #D2FFCF;">Generate Short URL on publish: <input id="urlshortlink" type="checkbox" name="get-shortlink" value="Enabled" /></div>');
			<?php }?>		

			$('.poplink').click(function(){ 
				var linkval = this.href;
				prompt('Short URL:', linkval); 
				return false;
			});	
			$('.remove-shorturl').click(function(){ 
				$('.shorturl-status strong').html('Removing....');
				return true;
			});
					
		});/* ]]> */</script>
	<?php	
	} else { //no service continue ?>
		<h4>Plugin Not Configured</h4>
		<p>Please proceed to the <a href="options-general.php?page=shorturl">URL Shortener options page</a> to select your desired URL Shortening Service</p>
		<script type="text/javascript">/* <![CDATA[ */ jQuery(document).ready(function($){
			$('#misc-publishing-actions').append('<div class="misc-pub-section">Short URL Status: <strong>Not Configured</strong></div><div style="padding: 1em; margin-top: 2em;background: #D2FFCF;">Please select your <a href="options-general.php?page=shorturl">URL Shortening Service</a></div>');
		});	/* ]]> */</script>
	<?php
	}
} else { //not enabled continue?>
	<p>Short URL generation using 3rd party services is currently <strong>disabled</strong></p>
	<p>To enable it, please proceed to the <a href="options-general.php?page=shorturl">URL Shortener options page</a> to select your desired URL Shortening Service</p>
<?php
}


		
			